package com.example.qxfw.slhx.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.zy.FireHistory;
import com.example.qxfw.slhx.service.LshzglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@ApiIgnore
@Api(tags = "森林火险--历史火灾管理")
@CrossOrigin
@RestController
@RequestMapping("/HistoricalFireManagementController")
public class HistoricalFireManagementController {
    @Autowired
    private LshzglService lshzglService;

    @ApiOperation("森林火险--历史火灾管理--表信息")
    @GetMapping("/getAllFireHistory")
    public SysResult getAllFireHistory() {
        List<FireHistory> list = lshzglService.getAllFireHistory();
        return SysResult.success(list);
    }

    @ApiOperation("森林火险--历史火灾管理--添加")
    @PostMapping("/insertOneData")
    public SysResult insertOneData(@RequestBody FireHistory fireHistory) {
        FireHistory result = lshzglService.insertOneData(fireHistory);
        if (result != null) {
            return SysResult.success(fireHistory);
        } else {
            return SysResult.fail("添加数据失败！！1");
        }
    }

    @ApiOperation("森林火险--历史火灾管理--修改")
    @PostMapping("/updateById")
    public SysResult updateById(@RequestBody FireHistory fireHistory) {
        FireHistory result = lshzglService.updateById(fireHistory);
        if (result != null) {
            return SysResult.success(result);
        } else {
            return SysResult.fail("更新数据失败！！！");
        }
    }

    @ApiOperation("森林火险--历史火灾管理--删除")
    @GetMapping("/deleteById")
    public SysResult deleteById(int id) {
        int result = lshzglService.deleteById(id);
        return SysResult.success(result);
    }


    @ApiOperation("森林火险--历史火灾管理--条件查询")
    @GetMapping("/attributeSearch")
    public SysResult attributeSearch(String fireName, String address, String stationName, float areaStart,
                                     float areaEnd, int popThreatStart, int popThreatEnd, float propertyThreatStart, float propertyThreatEnd) {
        List<FireHistory> result = lshzglService.attributeSearch(fireName, address, stationName, areaStart, areaEnd,
                popThreatStart, popThreatEnd, propertyThreatStart, propertyThreatEnd);
        return SysResult.success(result);
    }

    @ApiOperation("森林火险--历史火灾管理--多边形、矩形查询")
    @PostMapping("/conditionalQuery")
    public SysResult conditionalQuery(@RequestBody String[][] pos) {
        List<FireHistory> result = lshzglService.conditionalQuery(pos);
        return SysResult.success(result);
    }
}
